#include "card.hpp"

Card::Card(const unsigned int & card,const bool & p,const bool & t):type_card(card),have_piece(p),have_treasure(t)
{
}

bool Card::north_access() const
{
    if(type_card == 0 || type_card == 1 || type_card == 5 || type_card == 9)
        return false;

    return true;
}

bool Card::south_access() const
{
    if(type_card == 2 || type_card == 3 || type_card == 7 || type_card == 9)
        return false;

    return true;
}

bool Card::east_access() const
{
    if(type_card == 1 || type_card == 2 || type_card == 6 || type_card == 8)
        return false;

    return true;
}

bool Card::west_access() const
{
    if(type_card == 0 || type_card == 3 || type_card == 4 || type_card == 8)
        return false;

    return true;
}


bool Card::connexion_west_east(const Card & card_e) const
{
    return this->west_access() && card_e.east_access();
}

bool Card::connexion_south_north(const Card & card_n) const
{
    return this->south_access() && card_n.north_access();
}


void Card::clock_rotation()
{
    if(type_card <= 3)
        type_card=(type_card+1)%4;
    else if(type_card <= 7)
        type_card=4+(type_card+1)%4;
    else
        type_card=8+(type_card+1)%2;
}

void Card::anti_clock_rotation()
{
    if(type_card <= 3)
        type_card=(type_card-1)%4;
    else if(type_card <= 7)
        type_card=4+(type_card-1)%4;
    else
        type_card=8+(type_card-1)%2;
}

void Card::set_all(const Card & c)
{
    type_card=c.type_card;
    have_treasure=c.have_treasure;
    have_piece=c.have_piece;
}

void Card::set_all(const unsigned int & type,const bool & p,const bool & t)
{
    type_card=type;
    have_treasure=t;
    have_piece=p;
}

void Card::set_random_card_t0()
{
    type_card=random()%4;
}

void Card::set_random_card_t1()
{
    type_card=(random()%4)+4;
}

void Card::set_random_card_t2()
{
    type_card=(random()%2)+8;
}